<title>填报管理</title>
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb" lay-separator=">">
        <a lay-href=""><i class="layui-icon layui-icon-locate"></i>您当前的位置：</a>
        <a><cite>指标数据</cite></a>
        <a><cite>填报管理</cite></a>
    </div>
</div>

<div class="layui-fluid my-page-fillManage">
    <div class="manage-top">
        <div class="layui-card">
            <div class="layui-card-header">
                <div class="layui-header-title">
                    <i class="layui-icon fill-icon"></i>填报管理
                </div>
            </div>
            <div class="layui-card-body">
                <table id="fillManage-table" lay-filter="fillManage-table-filter"></table>
            </div>
        </div>
    </div>
    <div class="manage-bot">
        <div class="layui-card">
            <div class="layui-form" lay-filter="custom-indexdata-table">
                <div class="layui-card-body">
                    <div class="clearfix" style="overflow: hidden;">
                        <div class="layui-btn-container">
                            <button type="button" lay-submit class="layui-btn layui-btn-save" lay-filter="fill-data-submit">保存</button>
                            <button type="button" class="layui-btn layui-btn-history T-btn" data-target="history">历史数据查看</button>
                            <button type="button" class="layui-btn my-btn-audit bgColor T-btn" data-target="audit">
                                <i class="layui-icon layui-icon-upload-circle"></i>提交审核
                            </button>
                            <button type="button" class="layui-btn my-btn-upload bgColor" id="myUpload">
                                <i class="layui-icon layui-icon-upload"></i>上传附件
                            </button>
                        </div>
                        <div class="my-custom-deptFile scroll" id="deptFiles"></div>
                    </div>
                    <table id="my-custom-table" lay-filter="indicators-table"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .bgColor{
        background-color: #296ECA;
    }
    .manage-top .layui-table{
        width: 100%;
    }
    .layui-header-title{
        padding-left: 30px;
        position: relative;
    }
    .layui-card-header{
        height: 39px;
        line-height: 39px;
        border-bottom: 1px solid #D0D3DB;
    }
    .layui-card-header .fill-icon{
        width: 19px;
        height: 19px;
        background: url('/dist/style/res/param/fillManage/fill.png') no-repeat center center;
        background-size: cover;
        margin-top: -10px;
        left: 0px;
    }
    .layui-table-view .layui-table td, .layui-table-view .layui-table th{
        padding: 4px 0;
    }
    .manage-top .layui-table-cell{
		height: inherit;
	}
    .my-btn-audit, .my-btn-history, .my-btn-upload{
        width: 100px;
        height: 30px;
        line-height: 30px;
        padding: 0;
    }
    .manage-top .layui-badge {
		height: 23px;
		line-height: 23px;
		border-radius: 10px;
        padding: 0 21px;
	}
    .layui-table tbody tr.lineactive {
        background-color: #FDE7A3 !important;
    }
    .layui-table[lay-even] tbody tr:nth-child(odd) {
        background-color: #D3E5FF;
    }
    .layui-table[lay-even] tbody tr:nth-child(even) {
        background-color: #fff;
    }
    .layui-table[lay-even] tbody tr:nth-child(odd):hover, .layui-table[lay-even] tbody tr:nth-child(even):hover{
        background-color: #f2f2f2; 
    }
    .manage-bot{
        margin-top: 13px;
    }
    .manage-bot .layui-card{
        height: 658px;
    }
    .manage-bot tr td{
        vertical-align: middle;
    }
    .layui-btn-save{
        width: 68px;
        height: 30px;
        line-height: 30px;
        color: #FFFFFF;
        padding-left: 31px;
        background: url('/start/TheForm/css/img/form-save.png') no-repeat 9px 7px #2669B1;
        margin-right: 15px;
    }
    .layui-btn-history{
        width: 124px;
        height: 30px;
        line-height: 30px;
        color: #FFFFFF;
        padding-left: 30px;
        background: url('/dist/style/res/param/fillManage/history.png') no-repeat 9px 7px #2669B1;
    }
    .layui-btn-record{
        height: 28px;
        line-height: 28px;
        background-color: #2669B1;
        margin-left: 10px;
    }
    .noNumber{
        border-color: red;
    }
    .my-custom-deptFile{
        float: left;
        width: 500px;
        height: 30px;
        vertical-align: top;
        border: 1px solid #e6e6e6;
    }
    .manage-bot .layui-btn-container{
        float: left;
    }
    .my-custom-deptFile .unit-content {
        display: inline-block;
        padding: 2px 5px;
        padding-right: 15px;
        background-color: #ccc;
        position: relative;
        height: 20px;
        line-height: 20px;
        margin-bottom: 2px;
    }
    .my-custom-deptFile .unit-content:hover i{
        visibility: visible;
        color: red;
        font-weight: 600;
    }
    .my-custom-deptFile .unit-content:hover a {
        text-decoration: underline;
    }
    .my-custom-deptFile .unit-content i {
        position: absolute;
        right: 0px;
        top: -2px;
        font-size: 14px;
        cursor: pointer;
        visibility: hidden;
    }
    /* 文件上传 */
    .dataFill-upload{  
        word-wrap: break-word;
        white-space: pre-wrap;
        word-break: break-all;
        max-width: 100%;
        height: auto;
        overflow: hidden;
        color: #23559D;
    }
    .upLoadSucessBox{
        position: absolute;
        left: 14%;
        top: 26px;
        background: #000;
        display: none; 
        z-index: 9999;
        color: #fff;
    } 
    .upLoadSucessBox>div{
        padding: 3px 6px;
    }
    .upLoadSucessBox>div>span:nth-child(1){
        cursor: pointer;
    }
    .upLoadSucessBox>div>span:nth-child(1):hover{
        color: #8ca8c7;
       
        text-decoration: underline;
    }
    .delDataFillBtn{
        display: inline-block;
        margin-left: 8px;
        cursor: pointer;
        color: #db3e0d;
    }
    .dataFillfileBox .fileNumBox{
        display: none;
    }
</style>

<!-- 状态模板 -->
<script type="text/html" id="temporarystatusTpl">
	{{#
		var getStatusColor = function() {
			var mapColors = {
				'00': 'bgGreen',
				'20': 'layui-bg-blue',
				'25': 'layui-bg-orange',
				'30': 'layui-bg-orange',
				'40': 'layui-bg-cyan',
				'90': 'layui-bg-black',
				'99': 'layui-bg-black'
			};
			return mapColors[d.state] || '';
		};
	}}
	<span class="layui-badge {{getStatusColor()}}">{{d.statename}}</span>	
</script>

<!-- 附件模板 -->
<script type="text/html" id="temporaryenclosureTpl">
    {{#  if(!!d.fileMsg && d.fileMsg.length && d.fileMsg.length > 0){ 
        $.each(d.fileMsg, function(index, file) {
    }}
        <a class="T-btn" data-url="{{file.url}}" data-target="downFile" href="javascript:void(0);" lay-tips='{{file.filename}}'>{{file.filename}}</a>
    {{#  }) } else { }}
        
    {{#  } }}
</script>

<!-- 输入框模板 -->
<script type="text/html" id="datascore">
    {{# if(d.examine === 0){ }}
        <button type="button" class="layui-btn layui-btn-sm layui-btn-warn T-btn" data-target="examine" data-examine="{{d.examine_record}}"></button>
    {{# } }}
    <div class="layui-alg-select"></div>
    {{# if(!!d.write_value){ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value="{{d.write_value}}"/>
    {{# }else if(!!d.show_value){ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value="{{d.show_value}}"/>
    {{# }else if(!!d.datascore){ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value="{{d.datascore}}"/>
    {{# }else{ }}
        <input type="text" name="percent{{d.LAY_TABLE_INDEX}}" id="percent{{d.LAY_TABLE_INDEX}}" data-id="{{d.id}}" data-itemId="{{d.item_id}}" data-showVal="{{d.show_value}}" data-writeVal="{{d.write_value}}" class="layui-input my-input-style" value=""/>
    {{# } }}
    <span>请输入数值。</span>
</script>

<!-- 单位附件模板 -->
<script type="text/html" id="selectFileTpl">
	{{#
		layui.each(d, function(index,item) {
	}}
		<div class="unit-content">
			<a href="javascript: void(0);">{{item.filename}}</a>
			<i class="layui-icon layui-icon-close T-btn" data-target="delUnit" data-id="{{item.id}}"></i>
		</div>
	{{#
		})
	}}
</script>
<!-- 上传附件 --> 
<script type="text/html" id="fileUploadTem"> 
    <div class="dataFillfileBox">
        <a href="javascript:void(0)" class="dataFill-upload" id={{d.id}}>上传附件<span class="fileNumBox">(<i class="filenumberTxt"></i>)</span></a>
        <div class="upLoadSucessBox" ></div>
    </div>
</script>
<script>
    layui.use(['admin', 'table', 'tools', 'form', 'view','upload', 'laytpl', 'tableMerge'], function(){
        var admin = layui.admin,
            table = layui.table,
            tools = layui.tools,
            form = layui.form,
            view = layui.view,
            upload = layui.upload,
            laytpl = layui.laytpl,
            tableMerge = layui.tableMerge;

        var versionId = '',
            zbType = '',
            deptId = '',
            taskId = '',
            layout = ['.layui-table th', '.layui-table td'],
            indexFormData = [];
        
        form.render(null, 'custom-indexdata-table');

        initFillTable(); 
        initUpload();
        //鼠标移入事件
        $("body").delegate(".dataFillfileBox","mouseover",function(){
                $(this).find(".upLoadSucessBox").show();  
        })
        $("body").delegate(".dataFillfileBox","mouseout",function(){
            $(this).find(".upLoadSucessBox").hide();  
        })  
        //下载文件删除文件点击操作 
        $("body").delegate(".DataFilldownLoadFile","click",function(){//下载 
            var downLoadParam={  
                servername:$(this).parent().attr("servername"),
                filename:$(this).parent().attr("filename"),
                access_token: layui.data('layuiAdmin').access_token
            }  
            tools.downLoadfunction("myapi/DC/api/rest/web/custom/IndexFileDownloadAPI",downLoadParam,"下载文件");
        })
        $("body").delegate(".delDataFillBtn","click",function(){//删除 
            var parentDom=$(this).parent();
            var dataFillfileBox=$(this).parents(".dataFillfileBox")
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/IndexFileDelAPI',
                type: 'post',
                data: {
                    file_id:$(parentDom).attr("fileid"),  
	                servername:$(parentDom).attr("servername"),
                    access_token: layui.data('layuiAdmin').access_token,
                },
                success: function(res){  
                    layer.msg(res.data.retmsg, {time: 1500});  
                    if(res.retcode==0){//成功了   
                        var fileNumTxt=dataFillfileBox.find(".filenumberTxt").text(); 
                        if(fileNumTxt.length>0){
                            dataFillfileBox.find(".filenumberTxt").text(Number(fileNumTxt)-1);
                            if(Number(fileNumTxt)-1==0){
                                dataFillfileBox.find(".fileNumBox").hide();
                            }
                        }else{
                            dataFillfileBox.find(".filenumberTxt").text(1);
                        }
                        $(parentDom).remove();
                    }

                }
            })
        })
        //加载填报表单
        function initFillTable(taskid){
            var taskid = taskid || '';
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetIndexTaskByDept',
                done: function(res){
                    if(res.data.retcode == 0){
                        var data = res.data.data ? res.data.data : [];
                        table.render({
                            elem: '#fillManage-table',
                            height: 105,
                            even: true,
                            text: {
                                none: '<div class="no-data-tips"><img src="/dist/style/res/about/empty.png"><p style="color:#DBDBDB;">暂无数据</p></div>'
                            },
                            data: data,
                            cols: [
                                [{
                                    field: 'state',
                                    title: '状态',
                                    width: 120,
                                    align: 'center',
                                    templet: '#temporarystatusTpl'
                                }, {
                                    field: 'taskname',
                                    title: '任务名称',
                                    width: 200,
                                    align: 'center'
                                }, {
                                    field: 'dept_name',
                                    title: '填报单位',
                                    align: 'center'
                                }, {
                                    field: 'starttime',
                                    title: '开始时间',
                                    width: 150,
                                    align: 'center',
                                    templet: function(d) {
                                        return d.starttime.substring(0, 10)
                                    }
                                }, {
                                    field: 'endtime',
                                    title: '结束时间',
                                    width: 150,
                                    align: 'center',
                                    templet: function(d) {
                                        return d.endtime.substring(0, 10)
                                    }
                                }, {
                                    field: 'fileMsg',
                                    title: '附件名称',
                                    align: 'center',
                                    templet: '#temporaryenclosureTpl'
                                },{
                                    field: 'memo',
                                    title: '说明',
                                    align: 'center',
                                    templet: function(d){
                                        return '<span lay-tips="'+ d.memo +'">'+ d.memo +'</span>'
                                    }
                                }]
                            ],
                            done: function(res, custom, count){
                                if(res.data && res.count > 0){
                                    versionId = data[0].version_id;
                                    zbType = data[0].zbtype;
                                    deptId = data[0].dept_id;
                                    taskId = data[0].id;
                                    $('[lay-id="fillManage-table"]').find('tbody tr').eq(0).addClass('lineactive');
                                    initTable(taskId, deptId);
                                    if(taskid){
                                        layui.each(res.data, function(index, item){
                                            if(item.id == taskid){
                                                $('[lay-id="fillManage-table"] tbody tr').eq(index).addClass('lineactive');
                                                initDeptFiles(data[index].deptFileMsg);
                                            }
                                        })
                                    }else{
                                        initDeptFiles(data[0].deptFileMsg);
                                    }
                                }
                                tools.setFont(layout);
                            }
                        })
                    }
                }
            })
        }

        /*加载指标树状表格
        @param version_id 版本id
        @param zbtype 级别id
        @param dept_id 单位id
        */
        function initTable(taskid, dept_id){
            admin.req({
                url: 'myapi/DC/api/rest/web/custom/GetIndexForm',
                type: 'post',
                data: {
                    taskid: taskid,
                    dept_id: dept_id
                },
                done: function(res){
                    var leafs,fileMap;
                    if(res.data.retcode == 0){
                        var head = res.data.data.head,
                            data = res.data.data.data,
                            leafs = res.data.data.alg_leafs,
                            fileMap=res.data.data.fileMap,
                            toolCols = [ 
                                {field: 'datascore', templet: '#datascore', align: 'left', width: 300},
                                {type: 'checkbox', align: 'center', width: 200}, 
                                {field: '', templet: '#fileUploadTem', align: 'center', width: 300}
                            ];
                        getDataScore(data, indexFormData);
                        for(var i = 0; i < head.length; i++){
                            if(i == 0){
                                head[i].merge = true;
                            }else{
                                head[i].merge = [head[i-1].field, head[i].field];
                            }
                            head[i].minWidth = 200;
                            // head[i].width = 360;
                            head[i].align = 'center';
                            (function(i){ 
                                head[i].templet = function(d){
                                    var field = d[head[i].field];
                                    if(field != 'datascore'){
                                        return '<span lay-tips='+field+'>'+field+'</span>'
                                    }
                                };
                            })(i);
                        }  
                        head = head.concat(toolCols);  
                        table.render({
                            elem: '#my-custom-table',
                            height: 600,
                            text: {
                                none: '暂无数据'
                            },
                            limit: 10000,
                            data: data,
                            cols: [head],
                            done: function(res, curr, count){
                                if(res.data && res.data.length > 0){
                                    tableMerge.render(this);
                                    var allTrs = $('[lay-id="my-custom-table"] tbody tr'); 
                                    $.each(allTrs, function(index, item){
                                        var btnNode = '<button type="button" class="layui-btn layui-btn-record T-btn" data-target="record" data-id='+res.data[index].id+'>查看记录</button>';
                                        // $(this).find('td:last-of-type .layui-table-cell').append(btnNode);
                                        $(this).find('.laytable-cell-checkbox').append(btnNode);  
                                    })
                                    //加载上传附件的框
                                $('.dataFill-upload').each(function(i, el) { 
                                    var uploadFileUrl = 'myapi/DC/api/rest/web/custom/uploadfile';  
                                    if(!el.dropzone){ //已经绑定了文件上传
                                        tools.DropzoneUpload(el, uploadFileUrl, {}, success = function(res){   
                                            var eachTableData=data;
                                            var trIndex=$(el).parent().parent().parent().parent().index();  
                                            if(tools.isIE()){
                                                trIndex= $(el).parent().parent().parent().parent().parent().index();   
                                            }  
                                            var saveFileUrl="myapi/DC/api/rest/web/custom/IndexFileUploadingSaveAPI";
                                            admin.req({
                                                url: saveFileUrl,
                                                type: 'post',
                                                data: {
                                                    datascore_id:$(el).attr('id'),
                                                    servername:res.servername,
                                                    filename:res.filename,
                                                    access_token: layui.data('layuiAdmin').access_token
                                                },
                                                success: function(saveres){ 
                                                    if(saveres.data.retcode==0){ 
                                                        var saveres=saveres.data.data; 
                                                        var newEachFileItem='<div fileid='+saveres.id+'  servername='+saveres.servername+' filename='+saveres.filename+' ><span href="" class="DataFilldownLoadFile">'+saveres.filename+'</span><i  class="delDataFillBtn">X</i></div>';
                                                        if(tools.isIE()){
                                                            $(el).parent().siblings(".upLoadSucessBox").append(newEachFileItem); 
                                                        }else{
                                                            $(el).siblings(".upLoadSucessBox").append(newEachFileItem); 
                                                        }
                                                        $(".dataFillfileBox").parent(".layui-table-cell").css({"overflow":"visible"}); 
                                                        var fileNumTxt=$(el).find(".filenumberTxt").text(); 
                                                        if(fileNumTxt.length>0){
                                                            $(el).find(".filenumberTxt").text(Number(fileNumTxt)+1);
                                                        }else{
                                                            $(el).find(".filenumberTxt").text(1);
                                                        } 
                                                        $(el).find(".fileNumBox").show();
                                                        layer.msg('上传成功', {time: 1000});
                                                    }else{
                                                        layer.msg('上传失败！', {time: 1000});
                                                    }
                                                
                                                }
                                            })

                                            
                                        });
                                    }
                                    
                                });  
                                if(JSON.stringify(fileMap)!='{}'){ 
                                    //循环文件对象
                                    var newFileDataArr=[]; 
                                    for(var fileKey in fileMap){
                                        var newObj={};
                                        newObj.trId=fileKey; 
                                        newObj.fileData=fileMap[fileKey];
                                        newFileDataArr.push(newObj);
                                    }  
                                    for(var i=0;i<data.length;i++){
                                        for(var j=0;j<newFileDataArr.length;j++){
                                            if(newFileDataArr[j].trId==data[i].id){ 
                                                var eachFileData=newFileDataArr[j].fileData;
                                                for(var k=0;k<eachFileData.length;k++) {
                                                    var newEachFileItem='<div fileId='+eachFileData[k].id+' filename='+eachFileData[k].filename+' servername='+eachFileData[k].servername+' ><span  class="DataFilldownLoadFile">'+eachFileData[k].filename+'</span><i  class="delDataFillBtn">X</i></div>';
                                                    $(".dataFillfileBox").eq(i).find(".upLoadSucessBox").append(newEachFileItem);
                                                    $(".dataFillfileBox").parent(".layui-table-cell").css({"overflow":"visible"}); 

                                                    var fileNumTxt=$(".dataFillfileBox").eq(i).find(".filenumberTxt").text(); 
                                                    if(fileNumTxt.length>0){
                                                        $(".dataFillfileBox").eq(i).find(".filenumberTxt").text(Number(fileNumTxt)+1);
                                                    }else{
                                                        $(".dataFillfileBox").eq(i).find(".filenumberTxt").text(1);
                                                    } 
                                                    $(".dataFillfileBox").eq(i).find(".fileNumBox").show(); 
                                                }    
                                            }
                                        }
                                    }
                                } 
                                    initAlgSelect(leafs);
                                }
                                tools.setFont(layout);
                            }
                        })
                    }
                }
            })
        }

        //加载上传附件
        function initUpload(){
            var uploadInst = upload.render({
                elem: '#myUpload',
                url: 'myapi/DC/api/rest/web/custom/IndexUploadByDept?access_token='+layui.data('layuiAdmin').access_token,
                data: {
                    taskid: function(){
                        return taskId
                    },
                    access_token: layui.data('layuiAdmin').access_token
                },
                accept: 'file',
                before: function(obj){
                    layer.load();
                },
                done: function(res, index, upload){
                    if(res.retcode == 0){
                        initFillTable(taskId);
                    }else if(res.retcode == -2){
                        location.hash = '/user/login'
                    }
                    layer.msg(res.retmsg, {time: 1500});
                    layer.closeAll('loading');
                },
                error: function(index, upload){
                    layer.closeAll('loading'); 
                }
            })
        }

        /*
        加载单位已上传附件
        */
        function initDeptFiles(files){
            var view = document.getElementById('deptFiles'),
                getTpl = selectFileTpl.innerHTML;
            laytpl(getTpl).render(files, function(html){
                view.innerHTML = html;
            })
        }
        
        /*
        * 加载算法下拉框
        *@param leafs 下拉框的值
        */
        function initAlgSelect(leafs){
            var allScores = $('[lay-id="my-custom-table"] tbody tr td[data-field="datascore"]');
            for(var i in leafs){
                var leafId = leafs[i][0].item_id;
                layui.each(allScores, function(index, item){
                    var iptId = $(this).find('input').data('itemid'),
                        showValue = $(this).find('input').data('showval') || '',
                        writeValue = $(this).find('input').data('writeval') || '';
                    if(iptId == leafId){
                        var container = $(this).find('.layui-alg-select'),
                            html = "<select class='myAlgSelect' lay-ignore><option value='' data-type='1'></option>";
                        layui.each(leafs[i], function(i,each){
                            var newVal;
                            if(each.formula.indexOf("<")>0){
                                newVal = each.formula.replace('<', '< ');
                            }else{
                                newVal = each.formula;
                            }
                            if(each.formula == showValue){ 
                                html += "<option value='"+each.formula+"' data-writeVal='"+(writeValue ? writeValue : '')+"' data-type='"+each.item_value_type+"' data-id="+each.id+" selected>"+newVal+"</option>";
                            }else{
                                html += "<option value='"+each.formula+"' data-writeVal='"+(writeValue ? writeValue : '')+"' data-type='"+each.item_value_type+"' data-id="+each.id+">"+newVal+"</option>";
                            }
                        })
                        html += "</select>";
                        container.html(html);
                    }
                })
            }
            initAlgInput(); 
        }

        //为算法或值时显示隐藏输入框
        function initAlgInput(){
            var allSelects = $('.myAlgSelect');
            layui.each(allSelects, function(index, item){
                var selType = $(this).find('option:selected').data('type'),
                    iptVal = $(this).find('option:selected').data('writeval');
                $(this).parent().siblings('input').removeAttr('name');
                // if(selType == '1'){
                //      $(this).parent().siblings().not('button').removeClass('show').addClass('hidden');
                // }else{
                //     $(this).parent().siblings('input').val(iptVal).removeClass('hidden').addClass('show');
                //     $(this).parent().siblings('span').removeClass('show').addClass('hidden');
                // }
                if(selType == ''){
                     $(this).parent().siblings().not('button').removeClass('show').addClass('hidden');
                }else{
                    $(this).parent().siblings('input').val(iptVal).removeClass('hidden').addClass('show');
                    $(this).parent().siblings('span').removeClass('show').addClass('hidden');
                }
            })
        }

        //获取表格初始数据项值
        function getDataScore(data, array){
            layui.each(data, function(index, item){
                !!item.datascore && array.push({id: item.id, datascore: item.datascore});
            })
        }

        //保存表单时获取用户操作改变的数值
        function compareChange(oldData, newData){
            var result= [];
            for(var i = 0; i < oldData.length; i++){
                var obj = oldData[i],
                    num = obj.datascore,
                    flag = false;
                if(!!num){
                    for(var j = 0; j < newData.length; j++){
                        var n = newData[j].datascore;
                        if(n == num){
                            flag = true;
                            break;
                        }
                    }
                    if(!flag){
                        result.push(obj);
                    }
                }
            }
            return result;
        }

        //监听任务表格行单双击事件
		table.on('row(fillManage-table-filter)', function(obj){
            var data = obj.data;
			$('[lay-id="fillManage-table"]').find(obj.tr.selector).addClass('lineactive');
            $('[lay-id="fillManage-table"]').find(obj.tr.selector).siblings().removeClass('lineactive');
            versionId = data.version_id;
            zbType = data.zbtype;
            deptId = data.dept_id;
            taskId = data.id;
            initTable(taskId, deptId);
            initDeptFiles(data.deptFileMsg);
        })
         
        //点击事件
        $('.my-page-fillManage').delegate('.T-btn', 'click', function(){
            var target = $(this).data('target');
            switch(target){
                case 'downFile': 
                    var url = 'myapi/DC'+ $(this).data('url'),
                        name = $(this).text();
                    tools.downMethodfunction(url, name);
                break;
                case 'record': 
                    var id = $(this).data('id');
                    admin.req({
                        url: 'myapi/DC/api/rest/web/custom/GetIndexTaskOperatingData',
                        data: {
                            dataid: id
                        },
                        done:function(res){
                            var result = res.data;
                            if(result.retcode == 0){
                                if(result.data && result.data.length > 0){
									layer.open({
										id: 'temporary-addhtml',
										title:'<i class="formFill-icon"></i><span style="color:#FFF;">查看记录</span>',
										offset: '110px',
										type: 1,
										shadeClose: true,
										area: ['350px', '400px'],
										resize: false,
										success: function(lay, index){
											view(this.id).render('./task/temporary/history', {history: result.data});
										}
									})
								}else{
									layer.msg('暂无记录', {time: 1000});
								}
                            }
                        }
                    })
                break;
                case 'audit':
                    var checkStatus = table.checkStatus('my-custom-table'),
                        checkData = checkStatus.data;
                    if(checkData && checkData.length > 0){
                        layer.open({
                            id: 'usermemo',
                            type: 1,
                            title: '<i class="formFill-icon"></i><span style="color:#FFF;">补充说明</span>',
                            area: ['300px', '290px'],
                            offset: 'auto',
                            shadeClose: true,
                            resize: false,
                            success: function(lay, index){
                                view(this.id).render('./audit/components/usermemo', {
                                    showReview: false,
                                    title: '提交说明'
                                });
                            },
                            btn: ['确定', '取消'],
                            btnAlign: 'c',
                            yes: function(index, layero){
                                $('.layui-btn-save').trigger('click');
                                var memoval = $('#usermemo .layui-textarea').val(),
                                    auditVal = [];
                                layui.each(checkData, function(index, item){
                                    auditVal.push({ id: item.id, usermemo: memoval });
                                })
                                admin.req({
                                    url: 'myapi/DC/api/rest/web/custom/IndexTaskFillDataSubmitAudit',
                                    type: 'post',
                                    data: {
                                        data: JSON.stringify(auditVal)
                                    },
                                    success: function(res){
                                        if(res.data.retcode == 0){
                                            initTable(taskId, deptId);
                                            layer.msg(res.data.retmsg, {time: 1500});
                                        }
                                    }
                                });
                                layer.close(index);
                            },
                            btn2: function(index, layero){
                                layer.close(index);
                            }
                        })
                    }else {
                        layer.msg('请勾选需要提交审核的数据', {time: 1500});
                    }
                break;
                case 'delUnit':
                    var fileId = $(this).data('id');
                    admin.req({
                        url: 'myapi/DC/api/rest/web/custom/IndexTaskDeptFileDel',
                        type: 'post',
                        data: {
                            id: fileId
                        },
                        done: function(res){
                            if(res.data.retcode == 0){
                                initFillTable(taskId);
                                layer.msg(res.data.retmsg, {time: 1500});
                            }
                        }
                    })
                break;
                case 'examine':
                    var recordHtml = $(this).data('examine').replace(/</g, '&lt;').replace(/>/g, '&gt;');
                    layer.open({
                        id: 'examinePage',
                        title:'<i class="formFill-icon"></i><span style="color:#FFF;">格检详情</span>',
					    offset: '110px',
						type: 1,
						shadeClose: true,
					    area: ['400px', '300px'],
                        resize: false,
                        content: '<div class="layui-card-body">'+recordHtml+'</div>'
                    })
                break;
                default: 
                break;
            }
        })

        //监听算法下拉框change事件
        $('.my-page-fillManage').delegate('.myAlgSelect', 'change', function(){
            initAlgInput();
        });

        //监听submit提交
        form.on('submit(fill-data-submit)', function(data){
            delete data.field['app'];
            delete data.field['file'];
            delete data.field['layTableCheckbox'];
            var field = data.field,
                val = [],
                fillData = [],
                allSelects = $('.myAlgSelect');
            for(var i in field){
                if($.trim(field[i])){
                    var reg  = new RegExp(/^\d+(?=\.{0,1}\d+$|$)/);
                    if(!reg.test(field[i])){
                        $('#'+i).focus();
                        layer.msg('请输入数字', {time: 1500});
                        return ;
                    }
                    val.push(i);
                }
            }
            if(allSelects){
                layui.each(allSelects, function(index, item){
                    var selType = $(this).find('option:selected').data('type'),
                        dataId = $(this).parent().siblings('input').data('id') ? $(this).parent().siblings('input').data('id') : '',
                        selectId = $(this).find('option:selected').data('id') ? $(this).find('option:selected').data('id') : '',
                        selectVal = $(this).find('option:selected').val() ? $(this).find('option:selected').val() : '';
                    if(selType == '1'){ //值
                        fillData.push({ id: dataId, datascore: selectId, show_value: selectVal});
                    }else if(selType == '2'){ //2 为算法
                        var fillVal = $.trim($(this).parent().siblings('input').val());
                        fillData.push({ id: dataId, datascore: selectId, show_value: selectVal, write_value: fillVal });
                    }
                })
            }
            $.each(val, function(index, item){
                var id = $('#'+item).attr('data-id'),
                    datascore = $('#'+item).val();
                fillData.push({ id: id, datascore: datascore });
            })
            var result = compareChange(fillData, indexFormData);
            if(fillData && fillData.length > 0){
                admin.req({
                    url: 'myapi/DC/api/rest/web/custom/IndexTaskFillDataSave',
                    type: 'post',
                    data: {
                        data: JSON.stringify(result)
                    },
                    done: function(res){
                        if(res.data.retcode == 0){
                            initTable(taskId, deptId);
                            layer.msg(res.data.retmsg, {time: 1500});
                        }
                    }
                })
            }else {
                layer.msg('请填写数据', {time: 1500});
            }
        })
    })
</script>